package _1域对象;

import java.io.IOException;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/test1")
public class Test1Servlet extends HttpServlet{
	
	int count2 = 0;
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		int count1 = 0;
		count1++;
		resp.getWriter().println("test1 count1"+count1+"<br />");
		
		count2++;
		resp.getWriter().println("test1 count1=2"+count2+"<br />");
		
		
		//使用ServletContext
				//得到上下文对象
				ServletContext context = this.getServletContext();
				
				//取信息
				Integer allCount = (Integer)context.getAttribute("allCount");
				if(allCount==null) {
					allCount = 0;
				}
				allCount++;
				//存入信息
				context.setAttribute("allCount", allCount);
				
				resp.getWriter().print("allCount:"+allCount+"<br />");
			
	}

}
